package com.itheima.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class RabbitMQConfig {
        //定义交换机名称
        public static final String BLOG_UP_EXCHANGE = "blog_up_exchange";
        public static final String BLOG_ADD_EXCHANGE = "blog_add_exchange";


        //定义队列名称
        public static final String BLOG_DEL_QUEUE = "blog_del_queue";
        public static final String BLOG_DELUIDS_QUEUE = "blog_deluids_queue";

        public static final String BLOG_ADD_QUEUE = "blog_add_queue";


        //声明队列
        @Bean(BLOG_DEL_QUEUE)
        public Queue BLOG_DEL_QUEUE() {
            return new Queue(BLOG_DEL_QUEUE);
        }

        @Bean(BLOG_DELUIDS_QUEUE)
        public Queue BLOG_DELUIDS_QUEUE() {
            return new Queue(BLOG_DELUIDS_QUEUE);
        }

        @Bean(BLOG_ADD_QUEUE)
        public Queue BLOG_ADD_QUEUE() {
            return new Queue(BLOG_ADD_QUEUE);
        }

        //声明交换机
        @Bean(BLOG_UP_EXCHANGE)
        public Exchange BLOG_UP_EXCHANGE() {
            return ExchangeBuilder.fanoutExchange(BLOG_UP_EXCHANGE).durable(true).build();
        }

        @Bean(BLOG_ADD_EXCHANGE)
        public Exchange BLOG_ADD_EXCHANGE() {
            return ExchangeBuilder.fanoutExchange(BLOG_ADD_EXCHANGE).durable(true).build();
        }

        //队列与交换机的绑定
        @Bean
        public Binding DEL_BLOG_UP_EXCHANGE(@Qualifier(BLOG_DEL_QUEUE) Queue queue, @Qualifier(BLOG_UP_EXCHANGE) Exchange exchange) {
            return BindingBuilder.bind(queue).to(exchange).with("").noargs();
        }

        @Bean
        public Binding DELUIDS_BLOG_DEL_QUEUE(@Qualifier(BLOG_DELUIDS_QUEUE) Queue queue, @Qualifier(BLOG_UP_EXCHANGE) Exchange exchange) {
            return BindingBuilder.bind(queue).to(exchange).with("").noargs();
        }

        @Bean
        public Binding ADDUID_BLOG_ADD_EXCHANGE(@Qualifier(BLOG_ADD_QUEUE) Queue queue, @Qualifier(BLOG_ADD_EXCHANGE) Exchange exchange) {
            return BindingBuilder.bind(queue).to(exchange).with("").noargs();
        }
}
